"""
保单数据库模型
"""

from tortoise import Model, fields


class Policy(Model):
    """保单表"""
    policy_number = fields.CharField(pk=True, generated=False, max_length=128, unique=True, description="保单号")
    applicant_name = fields.CharField(max_length=128, description="投保人姓名")
    insured_name = fields.CharField(max_length=128, description="被保人姓名")
    insured_count = fields.IntField(description="被保人数")
    insured_date = fields.DateField(description="投保日期")
    start_date = fields.DateField(description="保单生效日期")
    end_date = fields.DateField(description="保单失效日期")
    premium = fields.DecimalField(max_digits=12, decimal_places=2, description="保费")
    occupation = fields.CharField(max_length=128, description="职业")
    # 与用户的关系，1对多关系 数据库会自动生成 salesman_job_number 字段  related_name="policies"表示在User模型中，通过policies字段可以访问到该用户的所有保单
    salesman = fields.ForeignKeyField("models.User", related_name="policies", description="销售员")
    company_id = fields.CharField(max_length=50, description="保险公司编号")
    product_id = fields.CharField(max_length=50, description="产品编号")
    risk_type_id = fields.CharField(max_length=50, description="险种编号")
    issuance_type_id = fields.CharField(max_length=50, description="出单类型编号")
    file_path = fields.CharField(max_length=255, description="保单文件路径")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")

    class Meta(Model.Meta):
        table = "policy"
        table_description = "保单表"
        ordering = ["-updated_at"]  # 按照更新时间降序排序




